package xyz.xtt.user.entity;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;

import org.apache.commons.lang3.StringUtils;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import xyz.xtt.user.api.enums.UserStatus;

/**
 * <p>
 * 用户基础信息表
 * </p>
 *
 * @author author
 * @since 2024-10-31
 */
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("tbl_user")
@ApiModel(value = "TblUser对象", description = "用户基础信息表")
public class TblUser implements Serializable {

	private static final long serialVersionUID = 1L;

	@ApiModelProperty(value = "id(uuid)")
	@TableId(value = "id", type = IdType.AUTO)
	private String id;

	@ApiModelProperty(value = "asset_user_id")
	private Long userId;

	@ApiModelProperty(value = "应用user_id")
	private Long appUserId;

	@ApiModelProperty(value = "手机号")
	private String phone;
	private String phoneBk;
	@ApiModelProperty(value = "邮箱地址")
	private String email;

	@ApiModelProperty(value = "登陆密码")
	private String loginPassword;

	@ApiModelProperty(value = "支付密码")
	private String payPassword;

	@ApiModelProperty(value = "用户状态{0：正常、1：禁用、2：注销、3、管理员}")
	private Integer status;

	@ApiModelProperty(value = "站内昵称")
	private String nickname;

	@ApiModelProperty(value = "头像[只包含文件名部分]")
	private String avatarUri;

	@ApiModelProperty(value = "性别 0:男、1：女、2：未知")
	private Integer gender;

	@ApiModelProperty(value = "国家")
	private String country;

	@ApiModelProperty(value = "省份")
	private String province;

	@ApiModelProperty(value = "城市")
	private String city;

	@ApiModelProperty(value = "经度")
	private String lon;

	@ApiModelProperty(value = "纬度")
	private String lat;

	@ApiModelProperty(value = "会员等级id")
	private Integer gradeId;

	@ApiModelProperty(value = "职业0：艺术家1：律师2、公务员3、法官")

	private String occupation;
	@ApiModelProperty(value = "渠道码：1000:通通app1001:others")
	private String channelCode;

	@ApiModelProperty(value = "邀请码")
	private String inviteCode;

	@ApiModelProperty(value = "注册时间")
	private LocalDateTime registerDatetime;

	@ApiModelProperty(value = "登入时间")
	private LocalDateTime loginDatetime;

	@ApiModelProperty(value = "最新修改时间")
	private LocalDateTime lastModifyDatetime;

	@ApiModelProperty(value = "用户姓名")
	private String userName;

	@ApiModelProperty(value = "身份证号")
	private String idCardNo;

	@ApiModelProperty(value = "认证状态")
	private Integer authStatus;

	@ApiModelProperty(value = "上次认证时间")
	private Long authBefore;

	@ApiModelProperty(value = "是否显示引导")
	private Integer guide;

	public String fieldVal(Function<TblUser, String> mapper) {
		return Optional.ofNullable(this).map(mapper).orElse(StringUtils.EMPTY);
	}

	public boolean syncUpdateCheck() {
		return StringUtils.isBlank(avatarUri) && StringUtils.isBlank(phone) && StringUtils.isBlank(userName);
	}

	public boolean checkStatus() {
		return Objects.equals(status, UserStatus.NORMAL.getCode());
	}

	public boolean checkGender() {
		return !filterGender();
	}

	public boolean filterGender() {
		return Objects.equals(gender, 1) || Objects.equals(gender, 2);
	}
}
